package com.itheima.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "检查组管理开发")  // 作用在类上
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;

    @ApiOperation(value = "检查项列表查询", notes = "根据客户端请求，完成检查项所有信息列表查询")//   添加业务方法上
    @GetMapping("checkgroup/findCheckItemInfoByGroupId/{id}")
    public Result findCheckItemInfoByGroupId(@PathVariable("id") int id) {

        return new Result(checkGroupService.findCheckItemInfoByGroupId(id));
    }

    @PostMapping("checkgroup/findPage")//post请求
    @ApiOperation(value = "分页查询", notes = "根据客户端请求，完成分页查询")//   添加业务方法上
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前分页页码", required = true, paramType = "form", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", required = true, paramType = "form", dataType = "Integer"),
            @ApiImplicitParam(name = "queryString", value = "查询条件", required = false, paramType = "form", dataType = "String")
    })
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        //条件查询

       // System.out.println(queryPageBean.getQueryString());
        return new Result(checkGroupService.findPage(queryPageBean)); //   total  +  List

    }


    @PostMapping("checkgroup/add")//通过有无id 执行添加可更改
    public Result add(@RequestBody CheckGroupDTO checkGroupDTO) { //接收前端发来的数据
        /* checkitem  有 id  托管态 执行 update xx set xxx? x? where id -?
         * checkitem  传来没有id 瞬时态 没有id 执行 save 方法 insert
         * */
        //更改后 添加或者修改的代码
        return new Result(checkGroupService.saveCheckGroup(checkGroupDTO));
    }


     @DeleteMapping("checkgroup/deleteCheckItemById/{id}")
    public  Result deleteCheckGroupById(@PathVariable("id")int id){

         return new Result(checkGroupService.updateCheckGroupById(id));
       }

     //套餐模块需要 的findall
    @GetMapping("checkgroup/findAll")
    public Result findAll(){
         //查询所有  返回一个集合
        return new Result(checkGroupService.list());
    }





}








